{include file='header'/}
<style>

    .layui-elem-quote {
        margin-left: 150px !important;
    }

    .d-flex {
        width: 100%;
        display: flex !important;
    }

    .layui-input-block {
        display: inherit;
    }

    .J-urlmodel1, .J-urlmodel2 {
        display: none;
    }
</style>
<body>
<form class="layui-form" action="javascript:;" onsubmit="return dosub(this)">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">URL 模式</label>
                <div class="layui-input-block">
                    <input lay-filter="url_mode" type="radio" name="row[url_mode]" value="0"
                           title="动态" {if $field.url_mode eq 0}checked="checked" {/if}>
                    <input lay-filter="url_mode" type="radio" name="row[url_mode]" value="1"
                           title="伪静态" {if $field.url_mode eq 1}checked="checked" {/if}>
                    <input lay-filter="url_mode" type="radio" name="row[url_mode]" value="2"
                           title="静态页面【未开发】" {if $field.url_mode eq 2}checked="checked" {/if}>
                </div>
                <tip class="J-urlmodel1" style="margin-left: 0 !important;display: none;">
                    注意：勾选伪静态后您的服务器必须配置URL重写才能正常访问
                </tip>
                <blockquote class="layui-elem-quote J-urlmodel2" style="display: none;">
                    1. 启用后栏目与文章在新增或修改都会按照规则生成静态页面。<br/>
                    2. 多语言情况下自动增加语言标识<br/>
                    3. 修改模板后请重新生成<br/>
                    4. 暂不支持非响应模板<br/>
                    5. 确保public目录下有写入的权限<br/>
                    6. 注意：切换到其他模式后生成的HTML不会删除，如果修改模板没有生效请检查访问的地址是否是生成的HTML文件。<br/>
                </blockquote>
            </div>

            <div class="layui-form-item J-urlmodel1" style="display: none;">
                <label class="layui-form-label">Url 格式</label>
                <div class="layui-input-block">
                    <div class="d-flex">
                        <input id="row[url_format]-2" type="radio" name="row[url_format]" value="1" title="当前目录"
                        <?php if($field['url_rewrite']=='1'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[url_format]-6" type="radio" name="row[url_format]" value="2"
                               title="多语言/当前目录"
                        <?php if($field['url_rewrite']=='2'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[url_format]-1" type="radio" name="row[url_format]" value="3"
                               title="父目录/当前目录"
                        <?php if($field['url_rewrite']=='3'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[url_format]-3" type="radio" name="row[url_format]" value="4"
                               title="多语言/父目录/当前目录"
                        <?php if($field['url_rewrite']=='4'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[url_format]-4" type="radio" name="row[url_format]" value="5" title="当前目录"
                        <?php if($field['url_rewrite']=='5'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[url_format]-0" type="radio" name="row[url_format]" value="0"
                               title="自定义【未开发】"
                        <?php if($field['url_rewrite']=='0'){echo "checked";} ?>
                        >
                    </div>
                </div>
                <tip>栏目名称：$name；网站名称：$site；页码：$page</tip>
            </div>

            <div class="layui-form-item J-urlmodel2">
                <label class="layui-form-label">栏目规则</label>
                <div class="layui-input-block">
                    <div class="d-flex">
                        <input id="row[html_column_rules]-1" type="radio" name="row[html_column_rules]" value="1"
                               title="父目录/子目录"
                        <?php if($field['html_column_rules']=='/[catdir]/[list]/index.html|/[catdir]/[list]/index_[page].html'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[html_column_rules]-2" type="radio" name="row[html_column_rules]" value="2"
                               title="目录名称"
                        <?php if($field['html_column_rules']=='/[list]/index.html|/[list]/index_[page].html'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[html_column_rules]-0" type="radio" name="row[html_column_rules]" value="-1"
                               title="自定义"
                        <?php if(!in_array($field['html_column_rules'],$htmlRules['category'])) {echo "checked";} ?>
                        >
                        <input type="text" placeholder="" class="layui-input"
                               style="width: 50%" name="row[html_column_rules_diy]" value="{if !in_array($field['html_column_rules'],$htmlRules['category'])}{$field['html_column_rules']}{/if}">
                    </div>
                </div>
            </div>

            <div class="layui-form-item J-urlmodel2">
                <label class="layui-form-label">内容规则</label>
                <div class="layui-input-block">
                    <div class="d-flex">
                        <input id="row[html_content_rules]-1" type="radio" name="row[html_content_rules]" value="1"
                               title="父级目录/子目录/文档ID"
                        <?php if($field['html_content_rules']=='/[catdir]/[list]/[id].html|/[catdir]/[list]/[id]_[page].html'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[html_content_rules]-2" type="radio" name="row[html_content_rules]" value="2"
                               title="目录名称/文档ID"
                        <?php if($field['html_content_rules']=='/[list]/[id].html|/[list]/[id]_[page].html'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[html_content_rules]-0" type="radio" name="row[html_content_rules]" value="-1"
                               title="自定义"
                        <?php if(!in_array($field['html_content_rules'],$htmlRules['content'])) {echo "checked";} ?>
                        >
                        <input type="text" placeholder="" class="layui-input"
                               style="width: 50%" name="row[html_content_rules_diy]" value="{if !in_array($field['html_content_rules'],$htmlRules['content'])}{$field['html_content_rules']}{/if}">
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">栏目标题格式</label>
                <div class="layui-input-block">
                    <div class="d-flex">
                        <input id="row[category_format]-6" type="radio" name="row[category_format]" value="$name"
                               title="栏目名称"
                        <?php if($field['category_format']=='$name'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[category_format]-2" type="radio" name="row[category_format]"
                               value="$name - $site"
                               title="栏目名称 - 网站名称"
                        <?php if($field['category_format']=='$name - $site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[category_format]-1" type="radio" name="row[category_format]"
                               value="$name - 第$page页 - $site"
                               title="栏目名称 - 第N页 - 网站名称"
                        <?php if($field['category_format']=='$name - 第$page页 - $site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[category_format]-3" type="radio" name="row[category_format]"
                               value="$name_第$page页"
                               title="栏目名称_第N页"
                        <?php if($field['category_format']=='$name_第$page页'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[category_format]-4" type="radio" name="row[category_format]"
                               value="$name_第$page页_$site"
                               title="栏目名称_第N页_网站名称"
                        <?php if($field['category_format']=='$name_第$page页_$site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[category_format]-5" type="radio" name="row[category_format]" value="-1"
                               title="自定义"
                        <?php if($field['category_format']=='-1'){echo "checked";} ?>
                        >
                        <input type="text" class="layui-input"
                               style="width: 50%" name="row[category_format_diy]"
                               value="{if !in_array($field['category_format'],['$name_第$page页_$site','$name - $site','$name - 第$page页 - $site','$name_第$page页','$name_第$page页_$site', '$name'])}{$field['category_format']}{/if}"
                               placeholder="示例：$name - 第$page页 - $site">
                    </div>
                </div>
                <tip>栏目名称：$name；网站名称：$site；内容标题：$title</tip>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">内容标题格式</label>
                <div class="layui-input-block">
                    <div class="d-flex">
                        <input id="row[content_format]-2" type="radio" name="row[content_format]" value="$title"
                               title="内容标题"
                        <?php if($field['content_format']=='$title'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[content_format]-5" type="radio" name="row[content_format]" value="$title - $site"
                               title="内容标题 - 网站名称"
                        <?php if($field['content_format']=='$title - $site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[content_format]-1" type="radio" name="row[content_format]"
                               value="$title - $name - $site"
                               title="内容标题 - 栏目名称 - 网站名称"
                        <?php if($field['content_format']=='$title - $name - $site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[content_format]-3" type="radio" name="row[content_format]" value="$title_$site"
                               title="内容标题_网站名称"
                        <?php if($field['content_format']=='$title_$site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[content_format]-4" type="radio" name="row[content_format]"
                               value="$title_$name_$site" title="内容标题_栏目名称_网站名称"
                        <?php if($field['content_format']=='$title_$name_$site'){echo "checked";} ?>
                        >
                    </div>
                    <div class="d-flex">
                        <input id="row[content_format]-6" type="radio" name="row[category_format]" value="-1"
                               title="自定义"
                        <?php if($field['content_format']=='-1'){echo "checked";} ?>
                        >
                        <input type="text" class="layui-input"
                               style="width: 50%" name="row[content_format_diy]"
                               value="{if !in_array($field['content_format'],['$title','$title - $site','$title - $name - $site','$title_$site','$title_$name_$site'])}{$field['content_format']}{/if}"
                               placeholder="示例：$name - 第$page页 - $site">
                    </div>
                </div>
            </div>
            <div class="layui-form-item J-urlmodel0">
                <label class="layui-form-label">前台入口文件</label>
                <div class="layui-input-block">
                    <input id="row[url_file]-1" type="radio" name="row[url_file]" value="1" title="显示(index.php)"
                    <?php if($field['url_file']=='1'){echo "checked";} ?>
                    >
                    <input id="row[url_file]-2" type="radio" name="row[url_file]" value="0" title="隐藏(index.php)"
                    <?php if($field['url_file']=='0'){echo "checked";} ?>
                    >
                </div>
                <tip style="margin-left:0 !important;">注意：勾选伪静态后您的服务器必须配置URL重写才能正常访问</tip>
            </div>
            <div class="layui-form-item J-urlmodel2">
                <label class="layui-form-label">保存目录</label>
                <div class="layui-input-block">
                    <input id="frm-home_title" type="text" class="layui-input" name="row[html_dir]" value="{$field['html_dir']}">
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm button-load" lay-submit=""
                    lay-filter="admin-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    var $ = layui.jquery
      , form = layui.form;

    var urlModel = '{$field.url_mode}';
    var modelMap = {
      0: '.J-urlmodel0',
      1: '.J-urlmodel1',
      2: '.J-urlmodel2'
    };

    function showModel(model) {
      Object.values(modelMap).forEach(className => $(className).hide());
      $(modelMap[model]).show();
    }

    showModel(urlModel);

    form.on('radio(url_mode)', function (data) {
      showModel(data.value);
    });

    $('#frm-home_title').change(function (e) {
      //$('.home_title-txt').html($(this).val() ? 'http:'+Config.root_host+'/'+$(this).val()+'/':Config.root_host);
    });

    window.dosub = function (obj) {
      var loading = layer.load(2);
      $.ajax({
        type: 'POST',
        url: "{:url('seo/index')}",
        data: $(obj).serialize(),
        dataType: "json",
        success: function (res) {
          layer.close(loading);
          console.log(res)
          if (res.code === 200) {
            layer.msg(res.msg, {icon: 1, time: 2000}, function () {
              if (res.url != '') {
                window.location.href = res.url;
              } else {
                window.location.reload();
              }
            })
          } else {
            layer.msg(res.msg, {icon: 2, time: 2000})
          }
        }
      });
    }

  });
</script>
</body>
</html>
